//
//  LGTeamManageCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/16.
//

#import "LGTeamManageCell.h"
#import "DCAvatar.h"
@interface LGTeamManageCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *myTeamLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;


@end

@implementation LGTeamManageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.iconView dc_setImageAvatarWithGroupId:LGNSString(dataDic[@"teamid"]) Source:dataDic[@"iconAry"]];
//    [self.iconView sd_setImageWithURL:[NSURL URLWithString:dataDic[@"icon"]] placeholderImage:defaultDoctorPic];
    NSString *title = [NSString stringWithFormat:@"%@（%@）",dataDic[@"title"],dataDic[@"nums"]];
    if([dataDic[@"isleader"] integerValue] == 1){
        //我的团队
        self.myTeamLabel.hidden = NO;
        title = (title.length>8)?[NSString stringWithFormat:@"%@...",[title substringToIndex:8]]:title;
        
    }else{
        self.myTeamLabel.hidden = YES;
        title = (title.length>15)?[NSString stringWithFormat:@"%@...",[title substringToIndex:15]]:title;
    }
    self.titleLabel.text = title;
}


-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.myTeamLabel];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.top.equalTo(self.contentView).offset(-10);
        make.bottom.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.width.height.equalTo(@(viewPix(42)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(20));
        make.centerY.equalTo(self.contentView);
    }];
    [self.myTeamLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(12));
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(viewPix(72)));
        make.height.equalTo(@(viewPix(24)));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(12)));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView);
        make.right.equalTo(self.tipView);
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]init];
        _iconView.backgroundColor = [UIColor colorWithString:@"#EEEEEE"];
        _iconView.cornerRidus = 5;
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)myTeamLabel{
    if(!_myTeamLabel){
        _myTeamLabel = [UILabel lableWithText:@"我的团队" colorString:@"#27B6D7" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _myTeamLabel.backgroundColor = [UIColor colorWithString:@"#ECF7FF"];
        _myTeamLabel.cornerRidus = 3;
    }
    return _myTeamLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E1E1E1"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
